package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.response.ReportDataResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/9/22.
 */

public class GetReportDataRequest extends Request<ReportDataResponse> {
    private String projectId;   //项目编号
//    private int report_type; //1-日报 2-周报 3-月报 4-季报 5-年报，传区间内的一个时间
//    private String current_date; //格式：YYYY-MM-dd
    private String start_time;
    private String end_time;
    public GetReportDataRequest(String projectId,String start_time,String end_time,Response.Listener<ReportDataResponse> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/report"), listener);
        this.projectId = projectId;
        this.start_time = start_time;
        this.end_time = end_time;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());
        addParam("access_token", CacheManager.getAccessToken());
        addParam("efairyproject_id", projectId);
        addParam("start_time", start_time);
        addParam("end_time", end_time);
        return super.getParams();
    }

    @Override
    protected ReportDataResponse parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<ReportDataResponse>() {
        }.getType());
    }

}

